package com.jiukuaidao.library.net;

import java.io.File;
import java.util.TreeMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;

/**
 * Author : H_Joker
 * Date : 2016/5/13
 * Description :
 */
public abstract class ApiBaseFileAbstract<T> implements IApi {

    protected TreeMap<String, RequestBody> mParams = new TreeMap<>();

    protected RetroCallBackImpl<T> mRetroCallBackImp = new RetroCallBackImpl<>();

    protected Call<RootResult<T>> api;

    public ApiBaseFileAbstract(MyRetroCallBack<T> myRetroCallBack) {
        mRetroCallBackImp.setCallBack(myRetroCallBack);
    }

    public ApiBaseFileAbstract<T> needBaseParams(boolean need) {
        if (need) {
            buildBaseParams();
        }
        return this;
    }

    protected void putFile(String key, String dir, String fileName) {
        File dirFile = new File(dir);
        File file = new File(dirFile, fileName);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file);
        mParams.put(key + "\"; filename=\"" + fileName, requestBody);
    }

    protected void putParam(String key, String value) {
        mParams.put(key, RequestBody.create(null, value));
    }

    @Override
    public void buildBaseParams() {

    }

    @Override
    public void aes() {

    }

    @Override
    public void start() {
        api = getCall();
        api.enqueue(mRetroCallBackImp);
    }

    abstract public Call<RootResult<T>> getCall();

}
